package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.finance.dto.rewrite.BillRecordRewriteDTO;
import com.wlyuan.finance.dto.rewrite.WaybillRewriteDTO;
import com.wlyuan.open.domain.source.utils.MappingOrder;
import com.wlyuan.open.dto.OpenPaySyncDTO;
import com.wlyuan.open.dto.finance.BillTransportDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author yuanzheng
 */
public class PayAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingOrder.class,
    })
    public interface Assembler {

        @Mappings({
                @Mapping(target = "id", source = "paymentId"),

                @Mapping(target = "upstream", source = "upStream"),
                @Mapping(target = "downstream", source = "downStream"),
        })
        BillRecordRewriteDTO assemble(OpenPaySyncDTO source);


        @Mappings({
                @Mapping(source = "transportId", target = "waybillId"),
                @Mapping(source = "from.fromTime", target = "fromTime"),
                @Mapping(source = "info.contractNo", target = "contractNo"),
                @Mapping(source = "to.consigneeName", target = "consigneeName"),
                @Mapping(source = "info.weightAddition", target = "additionWeight"),
                @Mapping(source = "info.volumeAddition", target = "additionVolume"),
                @Mapping(source = "info.valueAddition", target = "additionValue"),
                @Mapping(source = "info.totalWeight", target = "totalWeight"),
                @Mapping(source = "info.totalVolume", target = "totalVolume"),
                @Mapping(source = "info.totalValue", target = "totalValue"),
                @Mapping(source = "info.totalQuantity", target = "totalQuantity"),
                @Mapping(source = "cost.totalFee", target = "totalFee"),
                @Mapping(source = "cost.receiptFee", target = "receiptFee"),
                @Mapping(source = "cost.prepayFee", target = "prepayFee"),
                @Mapping(source = "cost.arrivePayFee", target = "arrivePayFee"),
                @Mapping(source = "cost.collectionFee", target = "collectionFee"),
                @Mapping(source = "cost.divideFee", target = "divideFee"),
                @Mapping(source = "cost.wholeFee", target = "wholeFee"),
                @Mapping(source = "cost.pickFee", target = "pickFee"),
                @Mapping(source = "cost.deliverFee", target = "deliverFee"),
                @Mapping(source = "cost.loadFee", target = "loadFee"),
                @Mapping(source = "cost.unloadFee", target = "unloadFee"),
                @Mapping(source = "cost.insureFee", target = "insureFee"),
                @Mapping(source = "cost.taxFee", target = "taxFee"),
                @Mapping(source = "cost.surchargeFee", target = "surchargeFee"),
                @Mapping(source = "info.createAt", target = "createAt"),
                @Mapping(source = "info.waybillType", target = "waybillType"),

                @Mapping(source = "from", target = "fromAddress"),
                @Mapping(source = "to", target = "toAddress"),

                @Mapping(source = "requirement", target = "requirements"),
                @Mapping(source = "downStream", target = "downstream"),

                @Mapping(source = "upStream", target = "upstream"),
                @Mapping(source = "upStream.split", target = "upstream.divided"),
                @Mapping(source = "upStream.combine", target = "upstream.combined"),
        })
        WaybillRewriteDTO assemble(BillTransportDTO source);

    }

    public static BillRecordRewriteDTO assemble(OpenPaySyncDTO source) {
        return ASSEMBLER.assemble(source);
    }

}
